package org.finir.fakturisanje.persistence.beans;

import java.io.Serializable;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.finir.fakturisanje.persistence.Faktura;
import org.finir.fakturisanje.persistence.Komitent;
import org.finir.fakturisanje.persistence.Preduzece;
import org.finir.fakturisanje.persistence.Skladiste;
import org.finir.fakturisanje.persistence.StavkaFakture;
import org.jboss.seam.annotations.Name;

@Entity
@Name("faktura")
public class FakturaBean implements Faktura, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Long id;
	private Skladiste skladiste;
	private Komitent komitent;
	private Date datum;
	private Date valuta;

	private String otpremnica;
	private String radniNalog;
	private String napomena;
	private Preduzece preduzece;
	private String ukupnoRecima;

	public String getUkupnoRecima() {
		return ukupnoRecima;
	}

	public void setUkupnoRecima(String ukupnoRecima) {
		this.ukupnoRecima = ukupnoRecima;
	}

	private Integer brojFakture;

	public Integer getBrojFakture() {
		return brojFakture;
	}

	public void setBrojFakture(Integer brojFakture) {
		this.brojFakture = brojFakture;
	}

	private List<StavkaFakture> stavkeFakture = new ArrayList<StavkaFakture>();

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getStavkeFakture()
	 */
	@OneToMany(targetEntity = StavkaFaktureBean.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "faktura")
	public List<StavkaFakture> getStavkeFakture() {
		return stavkeFakture;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setStavkeFakture(java.util.List)
	 */
	public void setStavkeFakture(List<StavkaFakture> stavkeFakture) {
		this.stavkeFakture = stavkeFakture;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getPreduzece()
	 */
	@ManyToOne(targetEntity = PreduzeceBean.class)
	public Preduzece getPreduzece() {
		return preduzece;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setPreduzece(domain.Preduzece)
	 */
	public void setPreduzece(Preduzece preduzece) {
		this.preduzece = preduzece;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getId()
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setId(java.lang.Long)
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getSkladiste()
	 */
	@ManyToOne(targetEntity = SkladisteBean.class)
	public Skladiste getSkladiste() {
		return skladiste;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setSkladiste(domain.Skladiste)
	 */
	public void setSkladiste(Skladiste skladiste) {
		this.skladiste = skladiste;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getKomitent()
	 */
	@ManyToOne(targetEntity = KomitentBean.class)
	public Komitent getKomitent() {
		return komitent;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setKomitent(domain.Komitent)
	 */
	public void setKomitent(Komitent komitent) {
		this.komitent = komitent;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getDatum()
	 */
	@Temporal(value = TemporalType.DATE)
	public Date getDatum() {
		return datum;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setDatum(java.util.Date)
	 */
	public void setDatum(Date datum) {
		this.datum = datum;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getValuta()
	 */
	@Temporal(value = TemporalType.DATE)
	public Date getValuta() {
		return valuta;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setValuta(java.util.Date)
	 */
	public void setValuta(Date valuta) {
		this.valuta = valuta;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getOtpremnica()
	 */
	public String getOtpremnica() {
		return otpremnica;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setOtpremnica(java.lang.String)
	 */
	public void setOtpremnica(String otpremnica) {
		this.otpremnica = otpremnica;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getRadniNalog()
	 */
	public String getRadniNalog() {
		return radniNalog;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setRadniNalog(java.lang.String)
	 */
	public void setRadniNalog(String radniNalog) {
		this.radniNalog = radniNalog;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#getNapomenta()
	 */
	public String getNapomena() {
		return napomena;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see domain.beans.faktura#setNapomenta(java.lang.String)
	 */
	public void setNapomena(String napomena) {
		this.napomena = napomena;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof FakturaBean)) {
			return false;
		}
		FakturaBean other = (FakturaBean) object;
		if ((this.id == null && other.id != null)
				|| (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		DateFormat dFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
		return this.getBrojFakture() + "          " + komitent.getNaziv()
				+ "         " + dFormat.format(datum);
	}

}
